module NewProcess.Core exposing (..)

import Html as H
import Html.Events as E
import Html.Attributes as HA

type alias Model =
  {name: String
  ,cost: String
  ,print: String}

empty_process : Model
empty_process = {name="",cost="",print=""}


type Msg
    = New_process_name String
    | New_process_cost String
    | Add_process

type OutSignal
  = No_signal
  | Add_process_signal Model


view : Model -> H.Html Msg
view model =
  H.div 
    [HA.id "adder"] 
    [ H.div 
        []
        [ H.text "名称: "
        , H.input [E.onInput New_process_name] [H.text (.name model)]
        , H.br [] []
        , H.text "耗时: "
        , H.input [E.onInput New_process_cost] [H.text (.cost model)]
        , H.br [] []
        , H.button [E.onClick Add_process] [H.text "确认添加"]
        ]
    ]

update : Msg -> Model -> ( Model, Cmd Msg, OutSignal )
update msg model =
  case msg of
    New_process_name name ->
      ({model | name = name},Cmd.none,No_signal)

    New_process_cost cost ->
      ({model | cost = cost},Cmd.none,No_signal)

    Add_process ->
      (model,Cmd.none,Add_process_signal model)
      -- ({model | print = "name: " ++ (.name model)},Cmd.none)